<template>
  <div class="homeswiper">
    <van-search
      class="my-search"
      v-model="keywords"
      placeholder="请输入搜索关键词"
      @keydown.enter="searchSong"
    />
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in bannerData" :key="item.id">
        <img :src="item.imageUrl" alt="" />
      </van-swipe-item>
    </van-swipe>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      keywords: "",
      bannerData: [],
    };
  },
  created() {
    this.getBanner();
  },
  methods: {
    getBanner() {
      axios
        .get("/api/banner", "")
        .then((res) => {
          console.log(res.data);
          this.bannerData = res.data.banners;
        })
        .catch((err) => {
          console.error(err);
        });
    },
    searchSong() {
      if (this.keywords == "") {
        alert("搜索关键字不能为空");
      } else {
        this.$router.push({
          name: "Search",
          params: { keywords: this.keywords },
        });
      }
    },
  },
};
</script>
<style scoped>
.my-search {
  padding: 15px 0;
  width: 94%;
  margin: 0 auto;
}
.my-search > .van-search__content {
  border-radius: 30px;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  text-align: center;
}
.my-swipe .van-swipe-item img {
  width: 94%;
  border-radius: 10px;
}
</style>
